package kr.co.redcircle.console.dialog.contents;

import kr.co.redcircle.console.dialog.ConsoleDialogContents;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

public class MessageDialogContents extends ConsoleDialogContents {

	public static final int ERROR = 0;
	public static final int INFOR = 1;
	public static final int WARRN = 2;
	public static final int QUEST = 3;
	
	protected Object result;
	private Text text;
	private CLabel lblNewLabel = null;
	private CLabel lblTitle =  null;
	private int diagMessageType;
	private String diagTitle;
	private String diagMessage;
	private Image mainImage;
	
	
	public MessageDialogContents(Composite parent, Integer style, Point dialogSize, Rectangle contentsBound) {
		super(parent, style, dialogSize, contentsBound);
	}

	public MessageDialogContents(Composite parent, int style) {
		super(parent, style);
	}

	@Override
	public void createContents(final Shell parent) {

		if (this.messageContent != null){
			this.diagMessage = this.messageContent.getMessage();
			this.diagTitle = this.messageContent.getTitle();
			this.diagMessageType = this.messageContent.getMessageType();
			this.mainImage = this.messageContent.getMainImage();
		}

		parent.setText(this.diagTitle);
		
		lblTitle = new CLabel(parent, SWT.NONE);
		lblTitle.setImage(SWTResourceManager.getImage(MessageDialogContents.class, "/kr/co/redcircle/icons/bullet-black.ico"));
		lblTitle.setBounds(80, 10, 354, 21);
		lblTitle.setText(this.diagTitle);
		
		text = new Text(parent, SWT.READ_ONLY | SWT.WRAP | SWT.MULTI);
		text.setEnabled(false);
		text.setEditable(false);
		text.setBounds(101, 37, 333, 69);
		text.setText(this.diagMessage);
		
		lblNewLabel = new CLabel(parent, SWT.NONE);
		lblNewLabel.setBounds(10, 10, 54, 54);
		
		if (mainImage == null){
			mainImage = getImage();
			if (mainImage != null){
				lblNewLabel.setImage(mainImage);
			}
		}else{
			lblNewLabel.setImage(mainImage);
		}
		
		Button btnNewButton_1 = new Button(parent, SWT.NONE);
		btnNewButton_1.setBounds((parent.getBounds().width - 76)/2, parent.getBounds().height - (25 + 40), 76, 25);
		btnNewButton_1.setText("Ok");
		btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				parent.close();
			}
		});

	}

	private Image getImage() {

		if (this.messageContent != null){
			this.messageContent.getMessage();
			text.setText(this.messageContent.getMessage());
		}
		
		Image mainImage = null;
		switch(this.diagMessageType){
		case ERROR : 
			mainImage = SWTResourceManager.getImage(MessageDialogContents.class, "/kr/co/redcircle/icons/r48/dialog-error-4.ico");
			break;
		case INFOR : 
			mainImage = SWTResourceManager.getImage(MessageDialogContents.class, "/kr/co/redcircle/icons/r48/dialog-information-3.ico");
			break;
		case WARRN : 
			mainImage = SWTResourceManager.getImage(MessageDialogContents.class, "/kr/co/redcircle/icons/r48/dialog-warning-panel.ico");
			break;
		case QUEST : 
			mainImage = SWTResourceManager.getImage(MessageDialogContents.class, "/kr/co/redcircle/icons/r48/emblem-question-red.ico");
			break;
		
		}
		return mainImage;
	}

	@Override
	public void setupMessageContents() {


	}
}
